package com.wizardOther;

import com.appclient.LoggedUserPooling;
import com.appclient.Role;
import com.wizardOther.Items.AddNewCarController;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Timer;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

/**
 *
 * @author Sawior
 */
public class OtherMenuScreenController implements Initializable, OtherControlledScreen {

    private OtherScreensController myController;
    @FXML
    private Button otherMessClients;
    @FXML
    private Button otherMessEmployee;
    @FXML
    private Button otherCar;
    @FXML
    private Button otherTariff;
    @FXML
    private Button BackUp;
    @FXML
    private Button printPass;
    @FXML
    private Button configurator;
    @FXML
    private Button otherEmployee;
    @FXML
    private Button otherAccData;
    @FXML
    private Button client;
    Timer timer;
    LoggedUserPoolingOther timeTask = new LoggedUserPoolingOther(this);

    @FXML
    private void handleButtonAction(ActionEvent event) {
        if (event.getSource() == otherMessClients) {
            myController.setScreen(OtherScreensFramework.EMAIL_CLIENT);
        }
        if (event.getSource() == otherMessEmployee) {
            myController.setScreen(OtherScreensFramework.EMAIL_EMPLOYEE);
        }
        if (event.getSource() == otherCar) {
            myController.setScreen(OtherScreensFramework.ADD_NEW_CAR);
        }
        if (event.getSource() == otherTariff) {
            myController.setScreen(OtherScreensFramework.ADD_NEW_TARRIF);
        }
        if (event.getSource() == BackUp) {
            myController.setScreen(OtherScreensFramework.BACK_UP);
        }
        if (event.getSource() == printPass) {
            myController.setScreen(OtherScreensFramework.PRINT);
        }
        if (event.getSource() == configurator) {
            myController.setScreen(OtherScreensFramework.CONFIGURATOR);
        }
        if (event.getSource() == otherEmployee) {
            myController.setScreen(OtherScreensFramework.ADD_NEW_EMPLOYEE);
        }
        if (event.getSource() == otherAccData) {
            myController.setScreen(OtherScreensFramework.ADD_NEW_ACCOUNTINGDATA);
        }
        if (event.getSource() == client) {
            myController.setScreen(OtherScreensFramework.CLIENT);
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        timer = new Timer(true);
        timer.schedule(timeTask, 1000, 20);
    }

    @Override
    public void setScreenParent(OtherScreensController screenParent) {
        myController = screenParent;
    }

    public void screenForUser(final String userType) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {

                if (userType.equals(Role.bookkeeper.getName())) {
                    setScreenForBookkeeper();
                }
                if (userType.equals(Role.admin.getName())) {
                    setScreenForAdmin();
                }
                if (userType.equals(Role.manager.getName())) {
                    setScreenForManager();
                }
                if (userType.equals(Role.porter.getName())) {
                    setScreenForPorter();
                }
            }

        });
    }

    public void setScreenForBookkeeper() {
        showButton(otherMessClients);
        showButton(otherMessEmployee);
        showButton(otherCar);
        hideButton(otherTariff);
        showButton(BackUp);
        hideButton(printPass);
        hideButton(configurator);
        hideButton(otherEmployee);
        showButton(otherAccData);
        showButton(client);
    }

    public void setScreenForAdmin() {
        //all visible

        showButton(otherMessClients);
        showButton(otherMessEmployee);
        showButton(otherCar);
        showButton(otherTariff);
        showButton(BackUp);
        showButton(printPass);
        showButton(configurator);
        showButton(otherEmployee);
        showButton(otherAccData);
        showButton(client);

    }

    public void setScreenForManager() {
        showButton(otherMessClients);
        showButton(otherMessEmployee);
        showButton(otherCar);
        showButton(otherTariff);
        showButton(BackUp);
        showButton(printPass);
        showButton(configurator);
        showButton(otherEmployee);
        showButton(otherAccData);
        showButton(client);
    }

    public void setScreenForPorter() {
        showButton(otherMessClients);
        showButton(otherMessEmployee);
        showButton(otherCar);
        showButton(otherTariff);
        showButton(BackUp);
        showButton(printPass);
        showButton(configurator);
        showButton(otherEmployee);
        showButton(otherAccData);
        showButton(client);
    }

    public void hideButton(Button b) {
        b.setVisible(false);
    }

    public void showButton(Button b) {
        b.setVisible(true);
    }

}
